<!--  -->
<template>
  <div class="userlist">
    <headers></headers>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="name" label="姓名" width="180"> </el-table-column>
      <el-table-column prop="date" label="注册时间" width="180">
      </el-table-column>
      <el-table-column prop="address" label="注册地址" width="180">
      </el-table-column>
      <el-table-column prop="power" label="权限"> </el-table-column>
    </el-table>
    <div class="pagebox">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pagenow"
        layout=" prev, pager, next, jumper"
        :total="counts"
        :page-size="3"
      >
      </el-pagination>
      <el-pagination layout="total" :total="counts"> </el-pagination>
    </div>
  </div>
</template>

<script>
import Header from "./header";
import { getAdminslist, getAlladmincount } from "../axios/api";
export default {
  data() {
    //这里存放数据
    return {
      tableData: [
        {
          power: "管理员",
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          power: "管理员",
          date: "2016-05-04",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1517 弄",
        },
        {
          power: "管理员",
          date: "2016-05-01",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1519 弄",
        },
      ],
      pagenow: 1,
      counts: 0,
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //组件
  components: {
    headers: Header,
  },
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    getadminlist: function () {
      var start = this.pagenow;
      getAdminslist({ offset: (start - 1) * 3, limit: 3 }).then((res) => {
        this.tableData = [];
        res.data.forEach((item, index) => {
          var tabledata = {};
          tabledata.power = item.admin;
          tabledata.name = item.user_name;
          tabledata.address = item.city;
          tabledata.date = item.create_time;
          this.tableData.push(tabledata);
        });
        // console.log(res);
      });
      getAlladmincount().then((res) => {
        this.counts = res.count;
      });
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pagenow = val;
      this.getadminlist();
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    this.getadminlist();
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style  lang='less'>
</style>